//前台调用
var $ =function(){
    return new Base();  //每次调用Base都会去new出一个新的对象
}

//基础库
function Base(){
    //创建数组，来保存元素节点或节点数组
    //Base.prototype.elements = [];   //把Base.prototype改为this,new出对象时设置为私有化，这样前面的样式不会被后面的覆盖
    this.elements = [];
}




//获取ID节点
Base.prototype.getId = function(id){
    this.elements.push(document.getElementById(id));
    return this;

}

//获取元素节点
Base.prototype.getTagName = function(tag){
    var tags = document.getElementsByTagName(tag);
    for(var i=0;i<tags.length;i++){
        this.elements.push(tags[i]);
    }
    return this;
}



//获取Class数组节点
Base.prototype.getByClass = function(className,idName){
    var node = null;
    if(arguments.length == 2){
        node = document.getElementById(idName);
    }else{
        node = document; //文档所有节点的父节点
    }

    var all = node.getElementsByTagName('*');
    for(var i=0;i<all.length;i++){
        if(all[i].className == className){
            this.elements.push(all[i]);
        }
    }

    return this;

}
   



//获取某一个节点
Base.prototype.getElement = function (num) {    
    var element = this.elements[num];
    this.elements = [];
    this.elements[0] = element;
    return this;
};


//设置CSS
Base.prototype.css = function(attr,value){
    for(var i=0;i<this.elements.length;i++){
        if(arguments.length == 1){
            if(typeof window.getComputedStyle != 'undefined'){
                return window.getComputedStyle(this.element[i],null)[attr];  //W3C
            }else if(typeof this.element[i].currentStyle != 'undefined'){
                return this.element[i].currentStyle[attr];  //IE
            }
        }
        this.elements[i].style[attr] = value;
    }
    
    return this;
}

//设置innerHTML
Base.prototype.html = function(str){
    for(var i=0;i<this.elements.length;i++){
        if(arguments.length == 0){
            this.elements[i].innerHTML;
        }
        this.elements[i].innerHTML = str;
    }
    return this;
}

//触发点击事件
Base.prototype.click = function(fn){
    for(var i=0;i<this.elements.length;i++){
        this.elements[i].onclick = fn;
    }
    return this;
}